package selectCoursebl;

import java.rmi.RemoteException;
import java.util.ArrayList;

import message.Message;

import selectCourseDataService.SelectCourseDataService;
import PO.SelectPO;
import PO.UserPO;
import VO.CourseVO;
import VO.SelectVO;
import VO.UserVO;
import dataFactory.DataFactory;

public class SelectCourse {
	
	public Message selectCourse(ArrayList<CourseVO> courseList,UserVO userVO) throws RemoteException {
		//
		DataFactory factory=new DataFactory();
		SelectCourseDataService scds=factory.getSelectCourseDataService();
		//
		ArrayList selectList=new ArrayList<SelectPO>();
		for(int i=0;i<courseList.size();i++){
			CourseVO courseVO=courseList.get(i);
			SelectPO selectPO=new SelectPO(courseVO.getCourseNO(),courseVO.getCourseName(),
					courseVO.getTeacher(),userVO.getId(),userVO.getName());
			selectList.add(selectPO);
		}
		return scds.add(selectList);
		
	}

	
	public Message recordScore(SelectVO selectVO, int score) throws RemoteException {
		//
		DataFactory factory=new DataFactory();
		SelectCourseDataService scds=factory.getSelectCourseDataService();
		//
		selectVO.setScore(score);
		SelectPO selectPO=new SelectPO(selectVO.getCourseNO(),selectVO.getCourseName(),
				selectVO.getTeacherName(),selectVO.getStudentId(),selectVO.getStudentName());
		selectPO.setScore(score);
		
		return scds.update(selectPO);
		
	}

	
	public ArrayList<SelectVO> studentShowCourse(UserVO userVO) throws RemoteException {
		//
		DataFactory factory=new DataFactory();
		SelectCourseDataService scds=factory.getSelectCourseDataService();
		//
		ArrayList<SelectPO> poList=scds.find(new UserPO(userVO.getId(),userVO.getCode(),userVO.getName(),userVO.getRole()));
		ArrayList<SelectVO> voList=new ArrayList<SelectVO>();
		for(int i=0;i<poList.size();i++){
			SelectPO po=poList.get(i);
			SelectVO vo=new SelectVO(po.getCourseNO(),po.getCourseName(),po.getTeacherName(),
					po.getStudentId(),po.getStudentName());
			voList.add(vo);
		}
		
		return voList;
	}

	
	public ArrayList<SelectVO> teacherShowCourse(UserVO userVO) throws RemoteException {
		//
		DataFactory factory=new DataFactory();
		SelectCourseDataService scds=factory.getSelectCourseDataService();
		//
		ArrayList<SelectPO> poList=scds.find(new UserPO(userVO.getId(),userVO.getCode(),userVO.getName(),userVO.getRole()));
		
		ArrayList<SelectVO> voList=new ArrayList<SelectVO>();
		for(int i=0;i<poList.size();i++){
			SelectPO po=poList.get(i);
			SelectVO vo=new SelectVO(po.getCourseNO(),po.getCourseName(),po.getTeacherName(),
					po.getStudentId(),po.getStudentName());
			voList.add(vo);
		}
		
		return voList;
	}


	

}
